package a2;

/**
 * An ellipse with integer dimensions.
 */
public class Ellipse {

	// Private components:

	private int major_axis;
	private int minor_axis;

	// Constructors:

	/**
	 * Create a new Ellipse with the specified major and minor axes.
	 * The axes must be non-negative.
	 * @require maj > 0 && min > 0
	 * @ensure major_axis = maj
	 * 		   minor_axis = min
	 */
	public Ellipse(int maj, int min) {
		assert(maj > 0 && min > 0);
		this.major_axis = maj;
		this.minor_axis = min;
	}

	// Queries:

	/**
	 * The major axis or length of this ellipse.
	 * @require major_axis > 0 
	 * @ensure major_axis >0	   
	 */
	public int majorAxis() {
		assert(major_axis>0);
		return major_axis;
	}

	/**
	 * The minor axis or width of this ellipse.
	 * @require minor_axis > 0 
	 * @ensure minor_axis >0	
	 */
	public int minor_axis() {
		assert(minor_axis >0);
		return minor_axis;
	}

	/**
	 * The area of this ellipse.
	 * @require major_axis > 0 && minor_axis > 0
	 * @ensure area > 0
	 */
	public double area() {
		double area =Math.PI * major_axis * minor_axis / 4;
		assert(area>0);
		return area;
	}

	/**
	 * The circumference of this ellipse.
	 * We use the approximation from
	 * http://en.wikipedia.org/wiki/Ellipse
	 * @require major_axis > 0 && minor_axis > 0
	 * @ensure circumference > 0
	 */
	public double circumference() {
		assert(major_axis > 0 && minor_axis > 0);
		final double a = major_axis / 2;
		final double b = minor_axis / 2;
		double factor = (a-b)/(a+b);
		factor = 3 * factor * factor;
		double circumference = Math.PI * (a+b) * (1 + factor/(10 + Math.sqrt(4-factor)) );

		return circumference;
	}
}